package com.nbsaas.boot.contoller;

import com.nbsaas.boot.app.api.apis.AppRoleMenuApi;
import com.nbsaas.boot.app.api.domain.request.AppRoleMenuRequest;
import com.nbsaas.boot.app.api.domain.request.AppRoleMenuSearch;
import com.nbsaas.boot.app.api.domain.response.AppRoleMenuResponse;
import com.nbsaas.boot.app.api.domain.simple.AppRoleMenuSimple;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *  对外控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/appRoleMenu")
public class AppRoleMenuController {


    @Resource
    private AppRoleMenuApi appRoleMenuApi;


    @RequiresPermissions("appRoleMenu")
    @RequestMapping("/search")
    public PageResponse<AppRoleMenuSimple> search(@RequestBody AppRoleMenuSearch request) {
        return appRoleMenuApi.search(request);
    }

    @RequiresPermissions("appRoleMenu")
    @RequestMapping("/list")
    public ListResponse<AppRoleMenuSimple> list(@RequestBody AppRoleMenuSearch request) {
        return appRoleMenuApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("appRoleMenu")
    @CreateData
    @RequestMapping("/create")
    public ResponseObject<AppRoleMenuResponse> create(@RequestBody @Validated(AddOperator.class) AppRoleMenuRequest request) {
        return appRoleMenuApi.create(request);
    }

    @RequiresPermissions("appRoleMenu")
    @UpdateData
    @RequestMapping("/update")
    public ResponseObject<AppRoleMenuResponse> update(@RequestBody @Validated(UpdateOperator.class) AppRoleMenuRequest request) {
        return appRoleMenuApi.update(request);
    }

    @RequiresPermissions("appRoleMenu")
    @RequestMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) AppRoleMenuRequest request) {
        return appRoleMenuApi.delete(request);
    }

    @RequiresPermissions("appRoleMenu")
    @RequestMapping("/view")
    public ResponseObject<AppRoleMenuResponse> view(@RequestBody @Validated(ViewOperator.class) AppRoleMenuRequest request) {
        return appRoleMenuApi.view(request);
    }
}